package cn.edu.zafu.bigdata.x.cxy;

import java.util.List;
import java.util.ArrayList;

public class FindMax {
    public static <T extends Comparable<T>> T findMax(List<T> list) {
        if (list == null || list.isEmpty()) {
            return null;
        }
        T max = list.get(0);
        for (T element : list) {
            if (element.compareTo(max) > 0) {
                max = element;
            }
        }
        return max;
    }

    public static void main(String[] args) {
        // 创建包含整数的列表并使用findMax方法查找最大值
        List<Integer> integerList = new ArrayList<>();
        integerList.add(342);
        integerList.add(1123);
        integerList.add(4432);
        integerList.add(154);
        integerList.add(567);
        Integer maxInteger = findMax(integerList);
        System.out.println("The maximum integer in the list is: " + maxInteger);

        // 创建包含字符串的列表并使用findMax方法查找最大值
        List<String> stringList = new ArrayList<>();
        stringList.add("January");
        stringList.add("February");
        stringList.add("March");
        stringList.add("April");
        String maxString = findMax(stringList);
        System.out.println("The maximum string in the list is: " + maxString);
    }
}

